<!-- 添加、编辑预警 -->
<template>
  <base-breadcrumb :title="$route.meta.title">
    <a-card>
      <WarningFormCard :form="form" :rules="rules" ref="WarningFormCard"></WarningFormCard>
    </a-card>
    <div class="tool-btns page-btn-right-top">
      <a-button class="ml20" :loading="loading" type="primary" @click="addWarningFormHandler"> 提交 </a-button>
      <a-button class="ml20" type="primary" @click="handleClose"> 关闭 </a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
import WarningFormCard from './components/WarningFormCard.vue'

import { insertSelective } from '@/api/project/warning'

import mixins from './mixins.js'
export default {
  name: 'warningForm',
  mixins: [mixins],
  data() {
    return {
      loading: false,
      form: {
        projectCode: '', // 项目编号
        projectId: '', // 项目id
        projectName: '', // 项目名称
        branchId: '', // 分公司id
        branchName: '', // 分公司名称

        basicInfo: '', // 项目基本情况

        warnInfo: '', // 工期预警信息

        warnLevel: undefined, // 预警级别
        receivingUnit: '', // 接收单位
        recipientName: '', // 接收人
        recipientId: '', // 接收人id

        creatorName: '', // 检查时间
        createTime: '', // 检查时间
        fileInfoList: [] // 附件信息
      },
      managersQuery: {
        branchId: '',
        projectId: ''
      },
      projectMangers: [],
      rules: {
        branchId: [{ required: true, message: '请选择分公司', trigger: 'change' }],
        projectId: [{ required: true, message: '请选择项目', trigger: 'change' }],
        basicInfo: [{ required: true, message: '请输入项目基本情况', trigger: 'change' }],
        warnInfo: [{ required: true, message: '请输入工期预警信息', trigger: 'change' }],
        warnLevel: [{ required: true, message: '请选择预警级别', trigger: 'change', type: 'number' }],
        recipientId: [{ required: true, message: '请选择接收人', trigger: 'change' }],
        region: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }]
      }
    }
  },

  components: { WarningFormCard },

  computed: {},

  created() {
    this.getCurrentData()
    // 检查人
    this.form.creatorName = this.userInfo.name
  },

  mounted() {},

  methods: {
    // 获取当前的日期
    getCurrentData() {
      this.form.createTime = this.moment().format('YYYY-MM-DD')
    },
    // 关闭
    handleClose() {
      this.$close()
    },
    // 添加预警
    addWarningFormHandler() {
      console.log(this.form)
      this.$refs.WarningFormCard.$refs.warningform.validate((valid) => {
        if (valid) {
          this.$confirm({
            title: '提交',
            content: '确定提交该预警？',
            onOk: async () => {
              this.loading = true
              insertSelective(this.form).then((res) => {
                this.loading = false
                this.$message.success('提交成功')
                this.$close()
              })
            }
          })
        }else {
          this.$message.warning("请填写完所有必填项信息")
        }
      })
    }
  }
}
</script>
<style lang='less' scoped>
/deep/.ant-form-item-children textarea.ant-input {
  border-color: #e4ac0b;
  background-color: #fff9e8;
}
/deep/.recipient-box {
  .ant-select-selection {
    border-color: #e4ac0b;
    background-color: #fff9e8;
  }
}
/deep/ .warning-level {
  .ant-select-selection {
    border-color: #e4ac0b;
    background-color: #fff9e8;
  }
}
/deep/ .ant-select-selection {
  border-color: #e4ac0b;
  background-color: #fff9e8;
}
</style>
